# !/usr/bin/python
# -*- coding: utf-8 -*-

# 汇总全部省份的信息写入到excel
import os

from 神方.province.安徽省招投标 import get_anhui_value
from 神方.province.河南省招投标 import get_henan_value
from 神方.province.湖北省招投标 import get_hubei_value
from 神方.util.date_util import *

# 获得当前年份
from 神方.util.write_excel import write_file

data = {
        "序号": ["省份", "城市", "日期", "行业", "内容"]
    }

now_year = get_now_year_date()
# 获得当前日期的前十天的日期
now_time_str = get_date(1, '%Y-%m-%d')
# mktime参数为struc_time,将日期转化为秒，
start_time = get_offset(now_time_str, '%Y-%m-%d')

# 获取河南省的招投标信息
def henan_province():
    url = 'http://www.zgazxxw.com/hn-001011l772-0.html'
    # 创建一个空的列表用来存放数据
    list_henan = []
    pageNum = 0
    list_henan = get_henan_value(url, pageNum, list_henan, now_year, start_time)
    return list_henan

# 获取安徽省的招投标信息
def anhui_province():
    url = 'https://www.e-jebao.com/notice/list.html?province=16&city=&page=1'
    # 创建一个空的列表用来存放数据
    list_anhui = []
    pageNum = 0
    list_anhui = get_anhui_value(url, pageNum, list_anhui, start_time)
    return list_anhui

# 获取湖北省的招投标信息
def hubei_province():
    url = 'http://www.hbggzy.cn/jydt/003001/003001002/moreinfo_jyxx.html'
    # 创建一个空的列表用来存放数据
    list_anhui = []
    pageNum = 0
    list_hubei = get_hubei_value(url, pageNum, list_anhui, start_time)
    return list_hubei


if __name__ == '__main__':

    #list_datas_all = henan_province() + anhui_province() + hubei_province()
    list_datas_all = henan_province() + hubei_province()
    # print(list_datas_all)

    # 把数据循环放入到字典中
    index = 1
    for list in list_datas_all:
        data[str(index)] = list
        index = index + 1

    # 判断excel文件是否存在
    now_time = get_now_date('%Y%m%d')
    file_path = 'D:\\招投标信息' + now_time_str.replace('-', '') + '-' + now_time + '.xls'
    if os.path.exists(file_path):
        print('删除文件')
        os.remove(file_path)
    # 写入excel文件
    write_file(file_path, data, '招投标信息')